package com.zretc.support.dao;

import com.zretc.support.entity.Joincourse;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.List;

@Repository
public interface JoincourseDao extends JpaRepository<Joincourse,Long>, JpaSpecificationExecutor<Joincourse>,
        CrudRepository<Joincourse,Long>, Serializable {

    @Query("select j from Joincourse j where j.user.userName like %?1%")
    Page<Joincourse> getJoincourseByPageByStu(String keywords, Pageable pageable);

    @Query("select j from Joincourse j where j.course.courseName like %?1%")
    Page<Joincourse> getJoincourseByPageByCla(String keywords, Pageable pageable);

    @Query("select j from Joincourse j where j.course.user.userId = ?1 and j.user.userName like %?2%" )
    Page<Joincourse> getJoincourseByTeacherByStu(String userId, String keywords, Pageable pageable);

    @Query("select j from Joincourse j where j.course.user.userId = ?1 and j.course.courseName like %?2%" )
    Page<Joincourse> getJoincourseByTeacherByCla(String userId, String keywords, Pageable pageable);

    @Query("select j from Joincourse j where j.user.userId = ?1 and j.course.courseName like %?2%")
    Page<Joincourse> getJoincourseByStudent(String userId, String keywords, Pageable pageable);

    List<Joincourse> findByUser_UserId(String userId);
}
